//
//  XMNewMobileViewController.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/3.
//

#import "XMNewMobileViewController.h"
#import "XMNewMobileView.h"
#import "XMNetwork+mine.h"
#import "XMNetwork+login.h"

@interface XMNewMobileViewController ()

@end

@implementation XMNewMobileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    XMNewMobileView *newMobileView = [[XMNewMobileView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:newMobileView];
    XMWeakSelf;
    newMobileView.commitBlock = ^(NSString * _Nonnull mobileStr, NSString * _Nonnull codeStr) {
        [weakSelf mobileChangeCommitWithMobile:mobileStr code:codeStr];
    };
    newMobileView.codeSendBlock = ^(NSString * _Nonnull mobileStr) {
        [weakSelf getMobileCodeWithMobile:mobileStr];
    };
}

//获取验证码
- (void)getMobileCodeWithMobile:(NSString *)mobile {
    [_Network getCodeWithPhoneNum:mobile
                             type:@"2"
                          success:^(id  _Nonnull responseObject) {
        [MBProgressHUD showSuccess:@"发送成功，请注意查收"];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

//更换手机号
- (void)mobileChangeCommitWithMobile:(NSString *)mobileStr
                                code:(NSString *)codeStr {
    XMWeakSelf;
    [_Network changeMobileWithNewMobile:mobileStr
                                   code:codeStr
                                success:^(id  _Nonnull responseObject) {
        [weakSelf.navigationController popToRootViewControllerAnimated:YES];
    } failire:^(NSError * _Nonnull error) {
        
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
